local skel = fk.CreateSkill {
  name = "lb_zero__jiaohui",
  max_branches_use_time = {
    ["round"] = {
      [Player.HistoryRound] = 3
    },
  },
}

Fk:loadTranslationTable {
  ["lb_zero__jiaohui"] = "狡慧",
  [":lb_zero__jiaohui"] = "每轮限三次，当一名角色造成伤害时，你可令其摸此次伤害数张牌，然后改为造成等量次1点伤害；发动时，你可以耗尽本轮〖狡慧〗的次数以令此伤害翻倍。",

  ["#lb_zero__jiaohui"] = "狡慧：%src 即将对 %dest 造成%arg点%arg2伤害，你可令其摸 %arg 张牌，然后改为造成 %arg 次1点伤害",
  ["#lb_zero__jiaohui-damage"] = "狡慧：%src 即将对 %dest 造成%arg点%arg2伤害，你可令其摸 %arg 张牌，然后改为造成 %arg 次1点伤害，<br>"..
  "或耗尽本轮〖狡慧〗的次数，令其摸 %arg3 张牌，改为造成 %arg3 次1点伤害",

  ["$lb_zero__jiaohui1"] = "哼，你要倒霉咯~",
  ["$lb_zero__jiaohui2"] = "小心吓一跳哦~",
}


skel:addEffect(fk.DetermineDamageCaused, {
  anim_type = "support",
  times = function(self, player)
    return 3 - player:usedSkillTimes(skel.name, Player.HistoryRound, "round")
  end,
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name) and target and skel:withinBranchTimesLimit(player, "round", Player.HistoryRound) and
        not data.isVirtualDMG
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local num = 1
    local use_num = 3 - player:usedSkillTimes(skel.name, Player.HistoryRound, "round")
    local choices = { tostring(data.damage) }
    if use_num > 1 then
      table.insert(choices, tostring(data.damage * 2))
    end
    local choice = choices[1]
    if #choices > 1 then
      table.insert(choices, "Cancel")
      choice = room:askToChoice(player, {
        choices = choices,
        skill_name = skel.name,
        prompt = "#lb_zero__jiaohui-damage:"
            .. target.id .. ":"
            .. data.to.id .. ":"
            .. data.damage .. ":"
            .. Fk:getDamageNatureName(data.damageType) .. ":"
            .. data.damage * 2,
      })
      if choice == "Cancel" then return end
      if table.indexOf(choices, choice) == 2 then
        num = use_num
      end
    else
      if not room:askToSkillInvoke(player, {
            skill_name = skel.name,
            prompt = "#lb_zero__jiaohui:"
                .. target.id .. ":"
                .. data.to.id .. ":"
                .. data.damage .. ":"
                .. Fk:getDamageNatureName(data.damageType)
          }) then
        return
      end
    end
    event:setCostData(self, { num = num, tos = { target } })
    return true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local use_num = event:getCostData(self).num
    player:addSkillBranchUseHistory(skel.name, "round", use_num)
    local num = data.damage
    if use_num > 1 then
      num = num * 2
    end
    data:preventDamage()
    target:drawCards(num, skel.name)
    for _ = 1, num, 1 do
      room:damage {
        from = target,
        to = data.to,
        damage = 1,
        skillName = skel.name,
      }
    end
  end,
})

return skel
